package com.ellricky.baselib.adapter.course

import android.os.Bundle
import android.view.View
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.JobTraining
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback
import com.ellricky.baselib.util.StringUtil

class JobTrainingChildFragment : BaseRefreshFragment<Void, BasePresenter<Void>, JobTraining>() {

    private lateinit var fileType: String
    private lateinit var type: String
    private lateinit var searchDate: String
    private var showTitle: Boolean = false

    override fun initUIView(view: View?) {
        super.initUIView(view)
        val bundle = arguments
        type = bundle?.getString(BaseConstant.KEY_TYPE) ?: ""
        showTitle = bundle?.getBoolean(BaseConstant.KEY_SHOW_TITLE) ?: false

        when (type) {
            BaseConstant.TYPE_JOB_TRAIN -> {
                fileType = bundle?.getString(BaseConstant.TYPE_JOB_TRAIN_INDEX) ?: "1"
            }
            BaseConstant.TYPE_ACTIVE -> {
                searchDate = StringUtil.conversionTime(System.currentTimeMillis(), "yyyy-MM")
                loadDataOnInit()
            }
            BaseConstant.TYPE_RECENTLY_COURSE -> {
                searchDate = StringUtil.conversionTime(System.currentTimeMillis(), "yyyy-MM")
                loadDataOnInit()
            }
        }
        if (!showTitle) {
            hideToolBar()
        } else {
            mTvTitle.text = "岗位培训"
        }
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<JobTraining> {
        return JobTrainingAdapter(activity!!)
    }

    override fun getUrlPath(): String {
        return ""
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap.put("action", getAction())
        if (type == BaseConstant.TYPE_JOB_TRAIN) {
            paramMap.put("file_type", fileType)
            paramMap.put("search_key", "")
        }

        if (type == BaseConstant.TYPE_ACTIVE) {
            paramMap.put("search_data", searchDate)
        }

        if (type == BaseConstant.TYPE_RECENTLY_COURSE) {
            paramMap.put("search_data", searchDate)
        }

        paramMap.put("eid", LocalCacheUtil.getUid())
    }

    private fun getAction(): String {
        return when (type) {
            BaseConstant.TYPE_JOB_TRAIN -> {
                "entryList"
            }
            BaseConstant.TYPE_ACTIVE -> {
                "activityDataList"
            }
            BaseConstant.TYPE_RECENTLY_COURSE -> {
                "courseDataList"
            }
            else -> {
                ""
            }
        }
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<JobTraining>(requireActivity(), false) {
            override fun onSuccess(data: MutableList<JobTraining>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }
        }
    }

    companion object {
        fun newInstance(bundle: Bundle? = null): JobTrainingChildFragment {
            val fragment = JobTrainingChildFragment()
            fragment.arguments = bundle
            return fragment
        }
    }
}